package com.situ.achievementsystem.project.service;

import java.util.List;


import com.situ.achievementsystem.project.dao.ProjectDao;
import com.situ.achievementsystem.project.model.ProjectModel;

public class ProjectService {

private ProjectDao dao = new ProjectDao();
	
	public String insert(ProjectModel model) {
		return selectModel(model) == null?dao.insert(model):"rgp";
	}
	
	public String delete(ProjectModel model) {
		return dao.delete(model);
	}
	
	public String update(ProjectModel model) {
		return dao.update(model);
	}
	
	public List<ProjectModel> selectList(ProjectModel model) {
		String code = model.getCode();
		code = code ==null || code.trim().isEmpty()?"":code;
		model.setCode("%" + code + "%");//"%" + code + "%"
		String name = model.getName();
		name = name ==null || name.trim().isEmpty()?"":name;
		model.setName("%" + name + "%");
		return dao.select(model);
	}
	
	public ProjectModel selectModel(ProjectModel model) {
		ProjectModel temp = new ProjectModel();
		temp.setCode(model.getCode());
		List<ProjectModel> list = dao.select(model);
		if(list==null || list.isEmpty())
			return null;
		return list.get(0);
	}
	
	public Integer selectCount(ProjectModel model) {
		ProjectModel m0 = new ProjectModel();
        String code = model.getCode();
        if (code == null)
            code = "";
        m0.setCode("%" + code + "%");
        String name = model.getName();
        if (name == null)
            name = "";
        m0.setName("%" + name + "%");
        return dao.selectCount(m0);
    }
}
